#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
    int deleteAndEarn(vector<int> &nums)
    {
        vector<int> arr(1e4 + 1, 0);
        auto f = arr;
        auto g = arr;
        for (auto &ch : nums)
        {
            arr[ch] += ch;
        }

        //下面进行填表
        for(int i=1;i<=1e4;i++)
        {
            f[i]=g[i-1]+arr[i];
            g[i]=max(f[i-1],g[i-1]);
        }
        return max(f[1e4],g[1e4]);
    }
};